package com.itheima.users;

import com.itheima.users.dao.UserDatabase;
import com.itheima.users.dao.UserDatabaseInFile;
import com.itheima.users.dao.UserDatabaseInMemory;
import com.itheima.users.service.UserService;
import com.itheima.users.service.UserServiceImpl;
import com.itheima.users.ui.UserCMDUI;
import com.itheima.users.ui.UserGUI;
import com.itheima.users.ui.UserUI;

public class Main {
    public static void main(String[] args) {
        System.out.println("程序启动了...");

////        UserDatabase userDB = new UserDatabase();
////
////        // 匿名对象，不需要赋值给变量
////        // User user = new User("admin", "123456");
////        userDB.save(new User("admin", "123456"));
////        userDB.save(new User("jack", "666666"));
////
////        User user = userDB.queryByUserId("admin");
////        if (user == null){
////            System.out.println("用户不存在！");
////            return;   // return直接跳出main方法
////        }
////        System.out.println(user.getId());
////        System.out.println(user.getUsername());
////        System.out.println(user.getPassword());
//
//        UserService service = new UserService();
//
//        Result result = service.register("jack", "666666");
//        if (result.issuccess()){
//            System.out.println("注册成功！");
//            User user = (User) result.getData();
//            System.out.println("用户编号：" + user.getId());
//        }
//
//
//        Result result2 = service.register("admin", "123456");
//        if (result2.issuccess()){
//            System.out.println("注册成功！");
//            User user = (User) result2.getData();
//            System.out.println("用户编号：" + user.getId());
//        }
//
//         result2 = service.login("admin", "123456");
//        if (result2.issuccess()){
//            System.out.println("登录成功！");
//            User user = (User) result2.getData();
//            System.out.println("用户编号：" + user.getId());
//            System.out.println("用户名：" + user.getUsername());
//        }

        UserDatabase userDatabase = new UserDatabaseInFile("users.txt");
        UserService service = new UserServiceImpl(userDatabase);
        UserUI userUI = new UserGUI(service);
        userUI.entrance();

        System.out.println("程序退出了...");
    }
}
